#include <math.h>
#include <iostream>

using std::cout;
using std::endl;

class Point;//类的前向声明

class Line
{
public:
    //此时没有看到Point的定义，所以Point此时还是一个不完整类型
    double distance(const Point &lhs, const Point &rhs);
    void setPoint(Point &pt, int ix, int iy);

private:
    int _iz;
};

//友元关系是单向的,友元关系没有传递性(A->B->C),友元不能被继承
class Point
{
    //友元之成员函数
    /* friend double Line::distance(const Point &lhs, const Point &rhs); */
    /* friend void Line::setPoint(Point &pt, int ix, int iy); */
    //3、友元的第三种形式：友元之友元类
    friend class Line;
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int = 0, int = 0)" << endl;
    }

    void setLine(Line &line, int iz)
    {
        /* line._iz = iz;//error */
    }

    void print() const
    {
        cout << "(" << this->_ix 
             << ", " << this->_iy
             << ")";
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};

double Line::distance(const Point &lhs, const Point &rhs)
{
    return hypot(lhs._ix - rhs._ix, lhs._iy - rhs._iy);
}

void Line::setPoint(Point &pt, int ix, int iy)
{
    pt._ix = ix;
    pt._iy = iy;
}

Point func()
{
    Point pt(1, 2);
    return pt;
}

void test()
{
    /* Line line;//左值，对象 */

    Point pt1(1, 2);
    Point pt2(4, 6);
    pt1.print();
    cout << "---->";
    pt2.print();
    /* cout << "之间的距离 : " << line.distance(pt1, pt2) << endl; */
    cout << "之间的距离 : " << Line().distance(pt1, pt2) << endl;

    cout << endl;
    //int a = 10;
    //int b = 20
    //int c = a + b;
    //针对于自定义类型而言，两个或者多个对象不能进行加减乘除
    //不能直接进行运算符
    /* Point pt3 = pt1 + pt2;//error */
}


int main(int argc, char **argv)
{
    test();
    return 0;
}

